package com.example.backend.common.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.context.event.ApplicationStartedEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class ApplicationStartupListener implements ApplicationListener<ApplicationStartedEvent> {

    @Override
    public void onApplicationEvent(ApplicationStartedEvent event) {
        Environment env = event.getApplicationContext().getEnvironment();
        String port = env.getProperty("server.port", "9090");
        String contextPath = env.getProperty("server.servlet.context-path", "");
        
        log.info("\n----------------------------------------------------------\n" +
                "\t应用启动成功!\n" +
                "\tSwagger文档: \thttp://localhost:{}{}/doc.html\n" +
                "\tKnife4j增强文档: \thttp://localhost:{}{}/doc.html\n" +
                "----------------------------------------------------------",
            port, contextPath, port, contextPath);
    }
} 